let Timestamp = new Date().getTime();
const webpack = require('webpack')
module.exports = {
  publicPath: '/task-produce/',
  chainWebpack: config => {
    // 发布模式
    config.when(process.env.NODE_ENV === 'production', config => {
      config
        .entry('app')
        .clear()
        .add('./src/main-prod.js')

      config.set('externals', {
        vue: 'Vue',
        'vue-router': 'VueRouter',
        axios: 'axios',
        lodash: '_',
        echarts: 'echarts',
        nprogress: 'NProgress',
        'vue-quill-editor': 'VueQuillEditor'
      })

      config.plugin('html').tap(args => {
        args[0].isProd = true
        return args
      })
    })
    // 开发模式
    config.when(process.env.NODE_ENV === 'development', config => {
      config
        .entry('app')
        .clear()
        .add('./src/main-dev.js')

      config.plugin('html').tap(args => {
        args[0].isProd = false
        return args
      })
    })
    // 给js和css配置Timestamp
    config.output.filename('js/[name].' + Timestamp + '.js').end()
    config.output.chunkFilename('js/[name].' + Timestamp + '.js').end()
    config.plugin('extract-css').tap(args => [{
      filename: `css/[name].${Timestamp}.css`,
      chunkFilename: `css/[name].${Timestamp}.css`
    }])
    // 给img配置Timestamp
    config.module.rule('images').use('url-loader').tap(options => {
      options.name = `img/[name].${Timestamp}.[ext]`
      options.fallback = {
        loader: 'file-loader',
        options: {
          name: `img/[name].${Timestamp}.[ext]`
        }
      }
      return options
    })
  },
  configureWebpack: {
    plugins: [
      new webpack.ProvidePlugin({
        'window.Quill': 'quill/dist/quill.js',
        'Quill': 'quill/dist/quill.js'
      }),
    ]
  }
}

